home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / tm.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  27KB  |  1,140 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATKeyboard Version 3.0                    ** */
  4. /* **            Copright (C) 1992-1993 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* **                    Tastaturtabellen-Editor                    ** */
  8. /* **                                                               ** */
  9. /* ******************************************************************* */
  10.  
  11. #include "ATKeyboard.h"
  12.  
  13. EXTERN LONG                  KickstartVersion;
  14. EXTERN UBYTE                 TastenTabelle[256];
  15. extern struct TextAttr       OpalFontDef;
  16. extern struct IntuiText      Trennlinie_Text;
  17. extern struct IntuiText      Wirklich_Text;
  18. extern struct Einstellungen  Einstellungen;
  19. extern struct KeyCodes      *KeyCodes;
  20. extern struct FileRequester *FileRequester;
  21. extern struct MenuItem       TM_Item[];
  22. struct KeyTab               *BackupKeys;
  23.  
  24. struct IntuiText TU_Text=
  25. {
  26.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  27.  "Rücknahme aller Aktionen",
  28. };
  29.  
  30. struct IntuiText Kopieren_Text=
  31. {
  32.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  33.  "Taste kopieren",
  34. };
  35.  
  36. struct IntuiText Tauschen_Text=
  37. {
  38.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  39.  "Tasten tauschen",
  40. };
  41.  
  42. struct IntuiText CodeTable_Text=
  43. {
  44.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  45.  "CodeTable-Datei",
  46. };
  47.  
  48. struct IntuiText Translator_Text=
  49. {
  50.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  51.  "Translator-Datei",
  52. };
  53.  
  54. struct IntuiText ML_Text=
  55. {
  56.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  57.  "Tastaturtabelle laden von",
  58. };
  59.  
  60. struct IntuiText MS_Text=
  61. {
  62.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  63.  "Tastaturtabelle sichern als",
  64. };
  65.  
  66. struct IntuiText TE_Text=
  67. {
  68.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  69.  "Übernehmen und Beenden",
  70. };
  71.  
  72. struct MenuItem TE_Item=
  73. {
  74.  NULL,
  75.  5,30,300,10,
  76.  HIGHIMAGE|ITEMENABLED|ITEMTEXT|COMMSEQ,
  77.  0L,
  78.  &TE_Text,
  79.  &Wirklich_Text,
  80.  'Q',NULL
  81. };
  82.  
  83. struct MenuItem Trennlinie02_Item=
  84. {
  85.  &TE_Item,
  86.  5,20,300,10,
  87.  HIGHNONE|ITEMTEXT,
  88.  0L,
  89.  &Trennlinie_Text,
  90.  NULL,
  91.  0,NULL
  92. };
  93.  
  94. struct MenuItem CS_Item=
  95. {
  96.  NULL,
  97.  180,14,250,10,
  98.  HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT,
  99.  0L,
  100.  &CodeTable_Text,
  101.  NULL,
  102.  'R',NULL
  103. };
  104.  
  105. struct MenuItem TS_Item=
  106. {
  107.  &CS_Item,
  108.  180,4,250,10,
  109.  HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT,
  110.  0L,
  111.  &Translator_Text,
  112.  NULL,
  113.  'S',NULL
  114. };
  115.  
  116. struct MenuItem CL_Item=
  117. {
  118.  NULL,
  119.  180,14,250,10,
  120.  HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT,
  121.  0L,
  122.  &CodeTable_Text,
  123.  NULL,
  124.  'W',NULL
  125. };
  126.  
  127. struct MenuItem TL_Item=
  128. {
  129.  &CL_Item,
  130.  180,4,250,10,
  131.  HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT,
  132.  0L,
  133.  &Translator_Text,
  134.  NULL,
  135.  'L',NULL
  136. };
  137.  
  138. struct MenuItem MS_Item=
  139. {
  140.  &Trennlinie02_Item,
  141.  5,10,300,10,
  142.  HIGHCOMP|ITEMENABLED|ITEMTEXT,
  143.  0L,
  144.  &MS_Text,
  145.  NULL,
  146.  0,&TS_Item
  147. };
  148.  
  149. struct MenuItem ML_Item=
  150. {
  151.  &MS_Item,
  152.  5,0,300,10,
  153.  HIGHCOMP|ITEMENABLED|ITEMTEXT,
  154.  0L,
  155.  &ML_Text,
  156.  NULL,
  157.  0,&TL_Item
  158. };
  159.  
  160. struct MenuItem Swap_Item=
  161. {
  162.  NULL,
  163.  5,20,300,10,
  164.  HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
  165.  0L,
  166.  &Tauschen_Text,
  167.  NULL,
  168.  'T',NULL
  169. };
  170.  
  171. struct MenuItem Copy_Item=
  172. {
  173.  &Swap_Item,
  174.  5,10,300,10,
  175.  HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
  176.  0L,
  177.  &Kopieren_Text,
  178.  NULL,
  179.  'C',NULL
  180. };
  181.  
  182. struct MenuItem TU_Item=
  183. {
  184.  &Copy_Item,
  185.  5,0,300,10,
  186.  HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
  187.  0L,
  188.  &TU_Text,
  189.  NULL,
  190.  'X',NULL
  191. };
  192.  
  193. struct Menu TBearbeiten_Menu=
  194. {
  195.  NULL,
  196.  140,0,130,10,
  197.  MENUENABLED,
  198.  "Bearbeiten",
  199.  &TU_Item
  200. };
  201.  
  202. struct Menu TDatei_Menu=
  203. {
  204.  &TBearbeiten_Menu,
  205.  5,0,130,10,
  206.  MENUENABLED,
  207.  "Datei",
  208.  &ML_Item
  209. };
  210.  
  211. #define MENU_DATEI 0
  212. #define ITEM_LADEN 0
  213. #define ITEM_SICHERN 1
  214. #define SUBITEM_TRANSLATOR 0
  215. #define SUBITEM_CODETABLE 1
  216. #define ITEM_ENDE 3
  217. #define MENU_BEARBEITEN 1
  218. #define ITEM_UNDO 0
  219. #define ITEM_KOPIEREN 1
  220. #define ITEM_TAUSCHEN 2
  221.  
  222. #define xITEMENABLED (0xffff-ITEMENABLED)
  223.  
  224. struct Image PImage;
  225.  
  226. struct PropInfo PInfo=
  227. {
  228.  AUTOKNOB|FREEVERT|PROPBORDERLESS,0,0,0,512
  229. };
  230.  
  231. struct Gadget Prop_Gadget=
  232. {
  233.  NULL,
  234.  365,40,68,80,
  235.  GADGHCOMP,
  236.  RELVERIFY,
  237.  PROPGADGET,
  238.  &PImage,NULL,NULL,
  239.  NULL,&PInfo,500,NULL
  240. };
  241.  
  242. UBYTE ST[8][40];
  243.  
  244. struct IntuiText Select_Text[8]=
  245. {
  246.   {2,0,AUTODRAWMODE,12,1,&OpalFontDef,&ST[0],NULL},
  247.   {2,0,AUTODRAWMODE,12,1,&OpalFontDef,&ST[1],NULL},
  248.   {2,0,AUTODRAWMODE,12,1,&OpalFontDef,&ST[2],NULL},
  249.   {2,0,AUTODRAWMODE,12,1,NULL,&ST[3],NULL},
  250.   {2,0,AUTODRAWMODE,12,1,NULL,&ST[4],NULL},
  251.   {2,0,AUTODRAWMODE,12,1,NULL,&ST[5],NULL},
  252.   {2,0,AUTODRAWMODE,12,1,NULL,&ST[6],NULL},
  253.   {2,0,AUTODRAWMODE,12,1,NULL,&ST[7],NULL}
  254. };
  255.  
  256. struct Gadget Select_Gadget[8]=
  257. {
  258.   {
  259.    &Select_Gadget[1],
  260.    10,40,340,10,
  261.    GADGHCOMP,
  262.    RELVERIFY,
  263.    BOOLGADGET,
  264.    NULL,NULL,&Select_Text[0],
  265.    NULL,NULL,0,NULL
  266.    },
  267.   {
  268.    &Select_Gadget[2],
  269.    10,50,340,10,
  270.    GADGHCOMP,
  271.    RELVERIFY,
  272.    BOOLGADGET,
  273.    NULL,NULL,&Select_Text[1],
  274.    NULL,NULL,1,NULL
  275.    },
  276.   {
  277.    &Select_Gadget[3],
  278.    10,60,340,10,
  279.    GADGHCOMP,
  280.    RELVERIFY,
  281.    BOOLGADGET,
  282.    NULL,NULL,&Select_Text[2],
  283.    NULL,NULL,2,NULL
  284.    },
  285.   {
  286.    &Select_Gadget[4],
  287.    10,70,340,10,
  288.    GADGHCOMP,
  289.    RELVERIFY,
  290.    BOOLGADGET,
  291.    NULL,NULL,&Select_Text[3],
  292.    NULL,NULL,3,NULL
  293.    },
  294.   {
  295.    &Select_Gadget[5],
  296.    10,80,340,10,
  297.    GADGHCOMP,
  298.    RELVERIFY,
  299.    BOOLGADGET,
  300.    NULL,NULL,&Select_Text[4],
  301.    NULL,NULL,4,NULL
  302.    },
  303.   {
  304.    &Select_Gadget[6],
  305.    10,90,340,10,
  306.    GADGHCOMP,
  307.    RELVERIFY,
  308.    BOOLGADGET,
  309.    NULL,NULL,&Select_Text[5],
  310.    NULL,NULL,5,NULL
  311.    },
  312.   {
  313.    &Select_Gadget[7],
  314.    10,100,340,10,
  315.    GADGHCOMP,
  316.    RELVERIFY,
  317.    BOOLGADGET,
  318.    NULL,NULL,&Select_Text[6],
  319.    NULL,NULL,6,NULL
  320.    },
  321.   {
  322.    &Prop_Gadget,
  323.    10,110,340,10,
  324.    GADGHCOMP,
  325.    RELVERIFY,
  326.    BOOLGADGET,
  327.    NULL,NULL,&Select_Text[7],
  328.    NULL,NULL,7,NULL
  329.    }
  330. };
  331.  
  332. struct Gadget Swap_Gadget=
  333. {
  334.  &Select_Gadget[0],
  335.  240,12,81,11,
  336.  GADGHCOMP,
  337.  RELVERIFY,
  338.  BOOLGADGET,
  339.  NULL,NULL,NULL,
  340.  NULL,NULL,3000,NULL
  341. };
  342.  
  343. struct Gadget Copy_Gadget=
  344. {
  345.  &Swap_Gadget,
  346.  150,12,81,11,
  347.  GADGHCOMP,
  348.  RELVERIFY,
  349.  BOOLGADGET,
  350.  NULL,NULL,NULL,
  351.  NULL,NULL,2000,NULL
  352. };
  353.  
  354. struct Gadget Test_Gadget=
  355. {
  356.  &Copy_Gadget,
  357.  10,12,81,11,
  358.  GADGHCOMP,
  359.  RELVERIFY,
  360.  BOOLGADGET,
  361.  NULL,NULL,NULL,
  362.  NULL,NULL,1000,NULL
  363. };
  364.  
  365. struct NewWindow TMWindow=
  366. {
  367.  75,25,450,128,
  368.  0,1,
  369.  GADGETUP|CLOSEWINDOW|VANILLAKEY|MENUPICK,
  370.  WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|ACTIVATE,
  371.  &Test_Gadget,NULL,"ATKeyboard - Tastaturtabellen Editor",
  372.  NULL,NULL,
  373.  450,128,450,128,
  374.  WBENCHSCREEN
  375. };
  376.  
  377. UBYTE Name[20];
  378. struct InputEvent ie=
  379. {
  380.  NULL,IECLASS_RAWKEY,0,0,0
  381. };
  382.  
  383. struct RawName
  384. {
  385.  WORD   Select;
  386.  UBYTE *Name;
  387. };
  388.  
  389. struct RawName RawName[]={
  390.  0x45,"Escape",
  391.  0x50,"F1",
  392.  0x51,"F2",
  393.  0x52,"F3",
  394.  0x53,"F4",
  395.  0x54,"F5",
  396.  0x55,"F6",
  397.  0x56,"F7",
  398.  0x57,"F8",
  399.  0x58,"F9",
  400.  0x59,"F10",
  401.  0x46,"Del",
  402.  0x5f,"Help",
  403.  0x41,"Backspace",
  404.  0x66,"Amiga links",
  405.  0x67,"Amiga rechts",
  406.  0x64,"Alt links",
  407.  0x65,"Alt rechts",
  408.  0x60,"Shift links",
  409.  0x61,"Shift rechts",
  410.  0x63,"Control",
  411.  0x62,"Caps Lock",
  412.  0x40,"Space",
  413.  0x42,"Tab",
  414.  0x44,"Return",
  415.  0x43,"Enter",
  416.  0x4c,"Cursor auf",
  417.  0x4f,"Cursor ab",
  418.  0x4e,"Cursor rechts",
  419.  0x4d,"Cursor links",
  420.  0x5a,"Num Lock",
  421.  0x5b,"Scroll Lock",
  422.  0x5d,"Print Screen",
  423.  0x3d,"7/Home",
  424.  0x3e,"8/Cursor auf",
  425.  0x3f,"9/Seite auf",
  426.  0x2d,"4/Cursor links",
  427.  0x2e,"5",
  428.  0x2f,"6/Cursor rechts",
  429.  0x1d,"1/End",
  430.  0x1e,"2/Cursor ab",
  431.  0x1f,"3/Seite ab",
  432.  0x0f,"0/Insert",
  433.  0x3c,"./Del",
  434.  0x4a,"Ziffernblock: +",
  435.  0x5e,"Ziffernblock: -",
  436.  0x5c,"Ziffernblock: /",
  437.  0x0e,NULL,
  438.  0x1c,NULL,
  439.  0x2c,NULL,
  440.  0x3b,NULL,
  441.  -1,NULL
  442. };
  443.  
  444.  
  445. /* Sondertastenname ermitteln */
  446. BOOL GetRawName(select)
  447.  UBYTE         select;
  448. {
  449.  REGISTER WORD i;
  450.  
  451.  for(i=0;RawName[i].Select!=-1;i++)
  452.   {
  453.    if(RawName[i].Select==select)
  454.     {
  455.      if(RawName[i].Name!=NULL) sprintf(&Name,"<%s>",RawName[i].Name);
  456.      return(TRUE);
  457.     }
  458.   }
  459.  return(FALSE);
  460. }
  461.  
  462.  
  463. /* Tastenname ermitteln */
  464. UBYTE *GetName(select)
  465.  UBYTE select;
  466. {
  467.  UBYTE byte;
  468.  UBYTE anz;
  469.  BOOL  res;
  470.  
  471.  strcpy(&Name,"");
  472.  res=GetRawName(select);
  473.  if((res==FALSE)&&(select>=0x00)&&(select<0x40))
  474.   {
  475.    ie.ie_Code=select;
  476.    anz=RawKeyConvert(&ie,&byte,1L,NULL);
  477.    if(anz==1) sprintf(&Name,"<%c>",byte);
  478.   }
  479.  return(&Name);
  480. }
  481.  
  482.  
  483. /* Gadget-Texte auf Länge prüfen */
  484. VOID CheckST()
  485. {
  486.  REGISTER UBYTE i,j,k;
  487.  
  488.  for(i=0;i<=7;i++)
  489.   {
  490.    k=strlen(&ST[i]);
  491.    for(j=k;j<38;j++) strcat(&ST[i]," ");
  492.   }
  493. }
  494.  
  495.  
  496. /* Hex-Zeichen in Zahl wandeln */
  497. UBYTE GetHex(chr)
  498.  UBYTE chr;
  499. {
  500.  
  501.  if((chr>='0')&&(chr<='9')) return(chr-48);
  502.  return(chr-55);
  503. }
  504.  
  505.  
  506. /* Editorzeile anzeigen */
  507. VOID PrintS(rp,select,value,upValue,phase,color)
  508.  struct RastPort *rp;
  509.  UBYTE            select;
  510.  UBYTE            value;
  511.  UBYTE            upValue;
  512.  UBYTE            phase;
  513.  UBYTE color;
  514. {
  515.  REGISTER WORD    i;
  516.  UBYTE            str[50];
  517.  
  518.  if(color==1) SelectStdFPen(rp); else SetAPen(rp,3);
  519.  switch(phase)
  520.   {
  521.    case 0:
  522.      sprintf(&str,"$%02lx -> $%02lx ($%02lx)     %s",select,value,upValue,GetName(select));
  523.     break;
  524.    case 1:
  525.      sprintf(&str,"$%02lx -> $%lx- ($--)     %s",select,value,GetName(select));
  526.     break;
  527.    case 2:
  528.      sprintf(&str,"COPY [$%02lx -> $%02lx ($%02lx)     %s]",select,value,upValue,GetName(select));
  529.     break;
  530.    case 3:
  531.      sprintf(&str,"SWAP [$%02lx -> $%02lx ($%02lx)     %s]",select,value,upValue,GetName(select));
  532.     break;
  533.   }
  534.  for(i=strlen(&str);i<45;i++) strcat(&str," ");
  535.  WriteText(rp,10,32,&str);
  536. }
  537.  
  538.  
  539. /* Editor-Reset */
  540. VOID ResetEditor(win,pos,refresh)
  541.  struct Window *win;
  542.  UBYTE          pos;
  543.  BOOL           refresh;
  544. {
  545.  REGISTER WORD i,j;
  546.  
  547.  for(i=pos,j=0;i<=(pos+7);i++,j++)
  548.   {
  549.    sprintf(&ST[j],
  550.    "$%02lx -> $%02lx ($%02lx)     %s",
  551.    i,
  552.    KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[i],
  553.    KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[i+BIT7],
  554.    GetName(i));
  555.   }
  556.  CheckST();
  557.  if(refresh==TRUE) RefreshGadgets(&Select_Gadget[0],win,NULL);
  558. }
  559.  
  560.  
  561. /* ASCII-Zeile schreiben */
  562. VOID AWrite(fh,tex)
  563.  struct FileHandle *fh;
  564.  UBYTE             *tex;
  565. {
  566.  Write(fh,tex,strlen(tex));
  567. }
  568.  
  569.  
  570. UBYTE *Logo[]=
  571. {
  572.  "***********************************************\n",
  573.  "****                                       ****\n",
  574.  "****    ATKeyboard 3.0 Translator File     ****\n"
  575. };
  576.  
  577.  
  578. /* Translator-Datei schreiben */
  579. VOID WriteTranslator(fh)
  580.  struct FileHandle *fh;
  581. {
  582.  REGISTER WORD      i;
  583.  UBYTE              buf[64];
  584.  
  585.  AWrite(fh,Logo[0]);
  586.  AWrite(fh,Logo[1]);
  587.  AWrite(fh,Logo[2]);
  588.  AWrite(fh,Logo[1]);
  589.  AWrite(fh,Logo[0]);
  590.  AWrite(fh,"\n\nPC    <- Amiga <- Taste\n-----------------------\n");
  591.  for(i=0;i<=0x7f;i++)
  592.   {
  593.    sprintf(&buf,"$%02lx   <- $%02lx   <- %s\n",
  594.            KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[i],
  595.            i,GetName(i));
  596.    AWrite(fh,&buf);
  597.   }
  598. }
  599.  
  600.  
  601. /* Zeile lesen */
  602. BOOL ReadLine(fh,tex)
  603.  struct FileHandle *fh;
  604.  UBYTE             *tex;
  605. {
  606.  REGISTER WORD      i,j,anz;
  607.  UBYTE              byte;
  608.  
  609.  anz=0;
  610.  for(i=0;i<79;i++)
  611.   {
  612.    j=Read(fh,&byte,1L);
  613.    if(j==0)
  614.     {
  615.      tex[anz]=0x00;
  616.      return(FALSE);
  617.     }
  618.    switch(byte)
  619.     {
  620.      case 13:
  621.      case 10:
  622.        tex[anz]=0x00;
  623.        return(TRUE);
  624.       break;
  625.      default:
  626.        tex[anz]=byte;
  627.        anz++;
  628.       break;
  629.     }
  630.   }
  631.  tex[79]=0x00;
  632.  return(TRUE);
  633. }
  634.  
  635.  
  636. /* Translator-Datei lesen */
  637. VOID ReadTranslator(win,fh,pos,select)
  638.  struct Window     *win;
  639.  struct FileHandle *fh;
  640.  UBYTE              pos;
  641.  UBYTE              select;
  642. {
  643.  REGISTER WORD      a,b,zeile;
  644.  REGISTER UBYTE     anz;
  645.  REGISTER BOOL      okay,res;
  646.  UBYTE              byte;
  647.  UBYTE              buf[80];
  648.  UBYTE              TBuffer[128];
  649.  UBYTE             *Titel;
  650.  
  651.  Titel=win->Title;
  652.  SetWindowTitles(win,"Lade Translator-Datei...",-1L);
  653.  okay=FALSE;
  654.  anz=0;
  655.  zeile=0;
  656.  while(okay==FALSE)
  657.   {
  658.    res=ReadLine(fh,&buf);
  659.    zeile++;
  660.    if(res==TRUE)
  661.     {
  662.      if(buf[0]=='$')
  663.       {
  664.        buf[1]=toupper(buf[1]);
  665.        buf[2]=toupper(buf[2]);
  666.        a=b=-1L;
  667.        if( ((buf[1]>='0')&&(buf[1]<='9')) || ((buf[1]>='A')&&(buf[1]<='F')) ) a=GetHex(buf[1]);
  668.        if( ((buf[2]>='0')&&(buf[2]<='9')) || ((buf[2]>='A')&&(buf[2]<='F')) ) b=GetHex(buf[2]);
  669.        if((a==-1L)||(b==-1L))
  670.         {
  671.          if(a==-1L) a=1; else a=2;
  672.          sprintf(&buf,"%ld, %ld. Zeichen.",zeile,a);
  673.          Requester("Formatfehler in Zeile",&buf,"Okay",NULL);
  674.          okay=TRUE;
  675.         }
  676.        TBuffer[anz]=(a*16)+b;
  677.        anz++;
  678.        if(anz==128) okay=TRUE;
  679.       }
  680.     }
  681.    else
  682.     {
  683.      okay=TRUE;
  684.     }
  685.   }
  686.  if(anz==128)
  687.   {
  688.    for(a=0;a<=127;a++)
  689.     {
  690.      if(TBuffer[a]>=BIT7) TBuffer[a]-=BIT7;
  691.      KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[a]=TBuffer[a];
  692.      KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[a+BIT7]=TBuffer[a]+BIT7;
  693.     }
  694.    ResetEditor(win,pos,TRUE);
  695.    PrintS(win->RPort,0,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[select],
  696.                        KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[select+BIT7],0,1);
  697.   }
  698.  else
  699.   {
  700.    sprintf(&buf,"%ld statt 128 Zeichen.",anz);
  701.    Requester("Die Translator-Datei enthält nur",&buf,"Okay",NULL);
  702.   }
  703.  SetWindowTitles(win,Titel,-1L);
  704. }
  705.  
  706.  
  707. /* Tasten-Test */
  708. VOID TastenTest()
  709. {
  710.  register struct Window       *win;
  711.  register struct IntuiMessage *msg;
  712.  REGISTER ULONG                Class;
  713.  REGISTER UWORD                Code,Qualifier,i;
  714.  REGISTER BOOL                 ende;
  715.  
  716.  ende=FALSE;
  717.  win=CreateStdWindow("Testen-Test  -> Bitte Eingaben machen <-",
  718.                      75,5,450,11,
  719.                      CLOSEWINDOW|RAWKEY,
  720.                      WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|ACTIVATE);
  721.  if(win!=NULL)
  722.   {
  723.    while(ende==FALSE)
  724.     {
  725.      WaitPort(win->UserPort);
  726.      msg=GetMsg(win->UserPort);
  727.      Class=msg->Class;
  728.      Code=msg->Code;
  729.      Qualifier=msg->Qualifier;
  730.      ReplyMsg(msg);
  731.      switch(Class)
  732.       {
  733.        case RAWKEY:
  734.          for(i=0;i<256;i++) TastenTabelle[i]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[i];
  735.          Taste(Code,Qualifier);
  736.         break;
  737.        case CLOSEWINDOW:
  738.          ende=TRUE;
  739.         break;
  740.       }
  741.     }
  742.    DeleteStdWindow(win);
  743.   }
  744. }
  745.  
  746.  
  747. /* Editor-Hauptprogramm */
  748. VOID TMEditor()
  749. {
  750.  register struct Gadget       *Gadget;
  751.  register struct Window       *win;
  752.  register struct IntuiMessage *msg;
  753.  register struct RastPort     *rp;
  754.  register struct FileHandle   *fh;
  755.  REGISTER UBYTE               *k;
  756.  REGISTER ULONG                Class;
  757.  REGISTER UWORD                Code,ItemNum,MenuNum,SubItemNum;
  758.  REGISTER WORD                 i,j,id,pos;
  759.  UBYTE                         Select,Phase,STNum,Value,UndoChar,copy;
  760.  BOOL                          ende,refresh,changed;
  761.  
  762.  BackupKeys=AllocMem(256,MEMF_CLEAR|MEMF_PUBLIC);
  763.  if(BackupKeys==NULL) return;
  764.  CopyMem(&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,BackupKeys,256);
  765.  Select=0;
  766.  Phase=0;
  767.  STNum=0;
  768.  Value=0;
  769.  copy=0;
  770.  changed=FALSE;
  771.  UndoChar=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[0];
  772.  PInfo.VertPot=0;
  773.  pos=0;
  774.  ResetEditor(NULL,0,FALSE);
  775.  win=OpenWindow(&TMWindow);
  776.  if(win!=NULL)
  777.   {
  778.    rp=win->RPort;
  779.    SetFont(rp,GetOpalFont());
  780.    DrawPTextBorder(win,10,12,80,10,"Test");
  781.    DrawPTextBorder(win,150,12,80,10,"Kopie");
  782.    DrawPTextBorder(win,240,12,80,10,"Tausch");
  783.    DrawPBorder(win,9,39,341,81);
  784.    DrawNBorder(win,364,39,69,81);
  785.    SetMenuStrip(win,&TDatei_Menu);
  786.    PrintS(rp,0,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[0],
  787.                KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[BIT7],
  788.                0,1);
  789.    ende=FALSE;
  790.    while(ende==FALSE)
  791.     {
  792.      WaitPort(win->UserPort);
  793.      msg=GetMsg(win->UserPort);
  794.      Class=msg->Class;
  795.      Code=msg->Code;
  796.      Gadget=msg->IAddress;
  797.      ReplyMsg(msg);
  798.      switch(Class)
  799.       {
  800.        case VANILLAKEY:
  801.          changed=TRUE;
  802.          Code=toupper(Code);
  803.          refresh=FALSE;
  804.          if(((Code>='0')&&(Code<='9')) || ((Code>='A')&&(Code<='F')))
  805.           {
  806.            switch(Phase)
  807.             {
  808.              case 0:
  809.                Value=GetHex(Code);
  810.                PrintS(rp,Select,Value,0,1,2);
  811.                Phase=1;
  812.               break;
  813.              case 1:
  814.                Value=(Value*16)+GetHex(Code);
  815.                if(Value>=BIT7) Value-=BIT7;
  816.                PrintS(rp,Select,Value,Value+BIT7,0,2);
  817.                KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select]=Value;
  818.                KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7]=Value+BIT7;
  819.                Phase=0;
  820.                refresh=TRUE;
  821.               break;
  822.             }
  823.           }
  824.          else if((Code==13)&&(Phase==1))
  825.           {
  826.            PrintS(rp,Select,Value,Value+BIT7,0,2);
  827.            KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select]=Value;
  828.            KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7]=Value+BIT7;
  829.            Phase=0;
  830.            refresh=TRUE;
  831.           }
  832.          else if(Code==27)
  833.           {
  834.            KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select]=UndoChar;
  835.            Phase=0;
  836.            PrintS(rp,Select,UndoChar,UndoChar+BIT7,0,1);
  837.            Value=UndoChar;
  838.            refresh=TRUE;
  839.           }
  840.          if(refresh==TRUE)
  841.           {
  842.            sprintf(&ST[STNum],"$%02lx -> $%02lx ($%02lx)     %s",Select,Value,Value+BIT7,GetName(Select));
  843.            CheckST();
  844.            RefreshGadgets(&Select_Gadget[STNum],win,NULL);
  845.           }
  846.         break;
  847.        case MENUPICK:
  848.          MenuNum=MENUNUM(Code);
  849.          ItemNum=ITEMNUM(Code);
  850.          SubItemNum=SUBNUM(Code);
  851.          switch(MenuNum)
  852.           {
  853.            case MENU_DATEI:
  854.              switch(ItemNum)
  855.               {
  856.                case ITEM_SICHERN:
  857.                  switch(SubItemNum)
  858.                   {
  859.                    case SUBITEM_CODETABLE:
  860.                      if(FileRequester!=NULL)
  861.                       {
  862.                        k=FileReq("CodeTable-Datei sichern:","#?.codetable");
  863.                       }
  864.                      else
  865.                       {
  866.                        k=StringAbfrage(FALSE,"Name der CodeTable-Datei:","");
  867.                       }
  868.                      if((strcmp(k,"")))
  869.                       {
  870.                        fh=Open(k,MODE_NEWFILE);
  871.                        if(fh!=NULL)
  872.                         {
  873.                          Write(fh,&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,256);
  874.                          Close(fh);
  875.                         }
  876.                        else
  877.                         {
  878.                          Requester("Konnte die CodeTable-Datei","nicht erstellen.","Okay",NULL);
  879.                         }
  880.                       }
  881.                     break;
  882.                    case SUBITEM_TRANSLATOR:
  883.                      if(FileRequester!=NULL)
  884.                       {
  885.                        k=FileReq("Translator-Datei sichern:","#?.translator");
  886.                       }
  887.                      else
  888.                       {
  889.                        k=StringAbfrage(FALSE,"Name der Translator-Datei:","");
  890.                       }
  891.                      if((strcmp(k,"")))
  892.                       {
  893.                        fh=Open(k,MODE_NEWFILE);
  894.                        if(fh!=NULL)
  895.                         {
  896.                          WriteTranslator(fh);
  897.                          Close(fh);
  898.                         }
  899.                        else
  900.                         {
  901.                          Requester("Konnte die Translator-Datei","nicht erstellen.","Okay",NULL);
  902.                         }
  903.                       }
  904.                     break;
  905.                   }
  906.                 break;
  907.                case ITEM_LADEN:
  908.                  switch(SubItemNum)
  909.                   {
  910.                    case SUBITEM_CODETABLE:
  911.                      if(FileRequester!=NULL)
  912.                       {
  913.                        k=FileReq("CodeTable-Datei laden:","#?.codetable");
  914.                       }
  915.                      else
  916.                       {
  917.                        k=StringAbfrage(FALSE,"Name der CodeTable-Datei:","");
  918.                       }
  919.                      if((strcmp(k,"")))
  920.                       {
  921.                        fh=Open(k,MODE_OLDFILE);
  922.                        if(fh!=NULL)
  923.                         {
  924.                          Read(fh,&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,256);
  925.                          changed=TRUE;
  926.                          Close(fh);
  927.                         }
  928.                        else
  929.                         {
  930.                          Requester("Konnte die CodeTable-Datei","nicht laden.","Okay",NULL);
  931.                         }
  932.                       }
  933.                     break;
  934.                    case SUBITEM_TRANSLATOR:
  935.                      if(FileRequester!=NULL)
  936.                       {
  937.                        k=FileReq("Translator-Datei laden:","#?.translator");
  938.                       }
  939.                      else
  940.                       {
  941.                        k=StringAbfrage(FALSE,"Name der Translator-Datei:","");
  942.                       }
  943.                      if((strcmp(k,"")))
  944.                       {
  945.                        fh=Open(k,MODE_OLDFILE);
  946.                        if(fh!=NULL)
  947.                         {
  948.                          ReadTranslator(win,fh,pos,Select);
  949.                          changed=TRUE;
  950.                          Close(fh);
  951.                         }
  952.                        else
  953.                         {
  954.                          Requester("Konnte die Translator-Datei","nicht laden.","Okay",NULL);
  955.                         }
  956.                       }
  957.                     break;
  958.                   }
  959.                 break;
  960.                case ITEM_ENDE:
  961.                  ende=TRUE;
  962.                 break;
  963.               }
  964.             break;
  965.            case MENU_BEARBEITEN:
  966.              switch(ItemNum)
  967.               {
  968.                case ITEM_UNDO:
  969.                  CopyMem(BackupKeys,&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,256);
  970.                  ResetEditor(win,pos,TRUE);
  971.                  PrintS(rp,0,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  972.                              KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],0,1);
  973.                 break;
  974.                case ITEM_KOPIEREN:
  975.                  copy=1; changed=TRUE;
  976.                  PrintS(rp,Select,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  977.                                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],2,1);
  978.                 break;
  979.                case ITEM_TAUSCHEN:
  980.                  copy=2; changed=TRUE;
  981.                  PrintS(rp,Select,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  982.                                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],3,1);
  983.                 break;
  984.               }
  985.             break;
  986.           }
  987.         break;
  988.        case GADGETUP:
  989.          id=Gadget->GadgetID;
  990.          switch(id)
  991.           {
  992.            case 500:
  993.              pos=PInfo.VertPot/512;
  994.              if(pos>=120) pos=120;
  995.              ResetEditor(win,pos,TRUE);
  996.             break;
  997.            case 1000:
  998.              ClearMenuStrip(win);
  999.              TastenTest();
  1000.              SetMenuStrip(win,&TDatei_Menu);
  1001.             break;
  1002.            case 2000:
  1003.              if(copy==1) { j=0; copy=0; } else { j=2; copy=1; }
  1004.              PrintS(rp,Select,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  1005.                               KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],j,1);
  1006.             break;
  1007.            case 3000:
  1008.              if(copy==2) { j=0; copy=0; } else { j=3; copy=2; }
  1009.              PrintS(rp,Select,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  1010.                               KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],j,1);
  1011.             break;
  1012.            default:
  1013.             if((id>=0)&&(id<=7))
  1014.              {
  1015.               switch(copy)
  1016.                {
  1017.                 case 1:
  1018.                   copy=0;
  1019.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[pos+id]     =KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select];
  1020.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[pos+id+BIT7]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7];
  1021.                   ResetEditor(win,pos,TRUE);
  1022.                  break;
  1023.                 case 2:
  1024.                   j=pos+id+BIT7;
  1025.                   i=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select];
  1026.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[pos+id];
  1027.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[j];
  1028.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[pos+id]=i;
  1029.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[j]=i+BIT7;
  1030.                   copy=0;
  1031.                   ResetEditor(win,pos,TRUE);
  1032.                  break;
  1033.                 default:
  1034.                   Select=pos+id;
  1035.                   Phase=0;
  1036.                   STNum=id;
  1037.                  break;
  1038.                }
  1039.               UndoChar=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  1040.               PrintS(rp,Select,UndoChar,UndoChar+BIT7,0,1);
  1041.              }
  1042.           }
  1043.         break;
  1044.        case CLOSEWINDOW:
  1045.          if(changed==TRUE)
  1046.           {
  1047.            ende=UsePrefs();
  1048.            if(ende==FALSE)
  1049.             {
  1050.              CopyMem(BackupKeys,&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,256);
  1051.             }
  1052.           }
  1053.          ende=TRUE;
  1054.         break;
  1055.       }
  1056.     }
  1057.    ClearMenuStrip(win);
  1058.    CloseWindow(win);
  1059.    for(i=0;i<256;i++) TastenTabelle[i]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[i];
  1060.   }
  1061.  FreeMem(BackupKeys,256);
  1062. }
  1063.  
  1064.  
  1065. /* Modusname ändern/Modus (de)aktivieren */
  1066. VOID TMOnOff()
  1067. {
  1068.  REGISTER ULONG                Class;
  1069.  REGISTER BOOL                 bool;
  1070.  REGISTER WORD                 i,j;
  1071.  UBYTE                        *Name[8];
  1072.  struct Gadget                *OnOff_Gadget[7];
  1073.  register struct Gadget       *g;
  1074.  register struct Window       *win;
  1075.  register struct IntuiMessage *msg;
  1076.  
  1077.  win=CreateStdWindow("ATKeyboard - Tastaturmodus (de)aktivieren",
  1078.                      75,20,450,140,CLOSEWINDOW,
  1079.                      WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
  1080.  if(win!=NULL)
  1081.   {
  1082.    SetFont(win->RPort,GetOpalFont());
  1083.    for(i=29,j=0;i<=119;i+=15,j++)
  1084.     {
  1085.      if(KeyCodes->KeyTab[j+1].Valid)
  1086.       {
  1087.        OnOff_Gadget[j]=CreateSToggleGadget(win,10,i,100,12,"Aktiv",j);
  1088.       }
  1089.      else
  1090.       {
  1091.        OnOff_Gadget[j]=CreateNToggleGadget(win,10,i,100,12,"Aktiv",j);
  1092.       }
  1093.     }
  1094.    for(i=15,j=0;i<=120;i+=15,j++)
  1095.     {
  1096.      Name[j]=CreateStringGadget(win,130,i,290,10,&KeyCodes->KeyTab[j].Name[2],30,100);
  1097.     }
  1098.    bool=FALSE;
  1099.    while(bool==FALSE)
  1100.     {
  1101.      WaitPort(win->UserPort);
  1102.      msg=GetMsg(win->UserPort);
  1103.      Class=msg->Class;
  1104.      g=msg->IAddress;
  1105.      switch(Class)
  1106.       {
  1107.        case CLOSEWINDOW:
  1108.          bool=TRUE;
  1109.         break;
  1110.       }
  1111.      ReplyMsg(msg);
  1112.     }
  1113.    bool=UsePrefs();
  1114.    DeleteStdWindow(win);
  1115.    if(bool==TRUE)
  1116.     {
  1117.      for(i=0;i<=6;i++)
  1118.       {
  1119.        if(OnOff_Gadget[i]->Flags & SELECTED)
  1120.         {
  1121.          TM_Item[i+1].Flags |= ITEMENABLED;
  1122.          KeyCodes->KeyTab[i+1].Valid=1;
  1123.         }
  1124.        else
  1125.         {
  1126.          TM_Item[i+1].Flags &= xITEMENABLED;
  1127.          KeyCodes->KeyTab[i+1].Valid=0;
  1128.         }
  1129.       }
  1130.      for(i=0;i<=7;i++)
  1131.       {
  1132.        strcpy(&KeyCodes->KeyTab[i].Name,"  ");
  1133.        strcpy(&KeyCodes->KeyTab[i].Name[2],Name[i]);
  1134.       }
  1135.      NeuerModus(Einstellungen.Tastaturmodus,FALSE);
  1136.     }
  1137.   }
  1138. }
  1139.  
  1140.